package app.dev.ems.manager.impl;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;

import app.dev.ems.data.dao.IUserDao;
import app.dev.ems.data.model.impl.User;
import app.dev.ems.manager.IUserManager;

@Transactional
public class UserManagerImpl extends BaseManagerImpl<User> implements IUserManager {

	private IUserDao userDao;

	public void setUserDao(IUserDao userDao) {
		super.setEntityDao(userDao);
		this.userDao = userDao;
	}

	@Transactional(readOnly = true)
	public User findUserByCredential(String username, String password) {
		Criterion criterion = Restrictions.and(Restrictions.eq("username", username), Restrictions.eq("password", password));
		List<User> users = userDao.get(criterion);
		if(users != null && users.size() > 0){
			return users.get(0);
		}
		return null;
	}
}
